﻿@using HPIT.RentHouse.DTO
@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Layout1.cshtml";
}

<article class="cl pd-20">
    <form action="@Url.Action("Add_AdminUser","AdminUsers")" method="post" class="form form-horizontal" id="form-admin-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员名字：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="Name" name="Name">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>手机：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="PhoneNum" name="PhoneNum">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>初始密码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="password" class="input-text" autocomplete="off" value="" placeholder="密码" id="PasswordHash" name="PasswordHash">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>确认密码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="password" class="input-text" autocomplete="off" placeholder="确认新密码" id="PasswordSalt" name="PasswordSalt">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>邮箱：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" name="Email" id="Email">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">城市编号：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box" style="width:150px;">
                    <select id="CityId" class="select" name="CityId" size="1">
                        <option value="null">总部</option>
                        @foreach (var item in ViewBag.CityList as List<HPIT.RentHouse.DTO.CitiesDTO>)
                        {
                            <option value="@item.Id">@item.Name</option>
                        }
                    </select>
                </span>
            </div>
        </div>
        @*<div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">城市编号：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box" style="width:150px;">
                    <select class="select" name="CityId" size="1">
                        <option value="1">郑州</option>
                        <option value="2">洛阳</option>
                        <option value="5">南阳</option>
                    </select>
                </span>
            </div>
        </div>*@
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>错误次数：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" name="LoginErrorTimes" id="LoginErrorTimes">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">角色权限：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <dl class="permission-list">
                    <dt>
                        <label>
                            选择权限
                        </label>
                    </dt>
                    <dd>
                    <dd>
                        <dl class="permission-list2" style="height:140px">
                            @foreach (RolesDTO roles in ViewBag.RolesList as List<RolesDTO>)
                            {
                                <dt>
                                    <label class="">
                                        <input type="checkbox" class="RolesIds" name="RolesIds" value="@roles.Id">
                                        @roles.Name
                                    </label>
                                </dt>
                            }
                        </dl>
                    </dd>
                </dl>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>
@section footScript{
    <script type="text/javascript">
        $(function () {
            $('.skin-minimal input').iCheck({
                checkboxClass: 'icheckbox-blue',
                radioClass: 'iradio-blue',
                increaseArea: '20%'
            });

            $("#form-admin-add").validate({
                rules: {
                    Name: {
                        required: true,
                        maxlength: 16
                    },
                    PhoneNum: {
                        required: true,
                    },
                    PasswordHash: {
                        required: true,
                    },
                    PasswordSalt: {
                        required: true,
                        equalTo: "#PasswordHash"
                    },
                    Email: {
                        required: true,
                        email: true,
                    },
                    CityId: {
                        required: true,
                    },
                    LoginErrorTimes: {
                        required: true
                    },
                },
                //不能为空
                messages: {
                    Name: {
                        required: "不能为空",
                        maxlength: "输入长度最多是16个字符串"
                    },
                    PhoneNum: {
                        required: "不能为空",
                        isMobile: "请输入正确的手机号码"
                    },
                    PasswordHash: {
                        required: "不能为空"
                    },
                    PasswordSalt: {
                        required: "不能为空",
                        equalTo: "两次密码不一致"
                    },
                    Email: {
                        email: "请输入正确的邮箱格式"
                    },
                    CityId: {
                        required: "不能为空"
                    },
                    LoginErrorTimes: {
                        required: "不能为空"
                    },
                },
                onkeyup: false,
                focusCleanup: true,
                success: "valid",
                submitHandler: function (form) {
                    $(form).ajaxSubmit({
                        success: function (data) {
                            console.log(data)
                            if (data.State == 1) {
                                parent.location.reload();
                            } else {
                                layer.msg(data.ErrorMessage, { icon: 2 })
                            }
                        }
                    });
                }
            })
        })
    </script>
}